import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:good_good_study/common/index.dart';
import 'package:good_good_study/pages/login_page.dart';
import 'package:good_good_study/provider/app_provider.dart';
import 'package:good_good_study/repository/http.dart';
import 'package:provider/provider.dart';

class MinePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: SizedBox(),
        title: Text("我的"),
        centerTitle: true,
      ),
      body: Consumer<AppProvider>(
        builder: (context, app, child) {
          return Container(
            child: Column(
              children: [
                Center(
                  child: Text(app.userLoginData?.username ?? "未登录"),
                ),
                Center(
                  child: Text(app.userLoginData?.id?.toString() ?? "未登录"),
                ),
                (app.userLoginData?.username?.isEmpty ?? true)
                    ? RaisedButton.icon(
                        onPressed: () {
                          RouteUtil.push(context, LoginPage());
                        },
                        icon: Icon(Icons.local_gas_station),
                        label: Text("登录"))
                    : RaisedButton(
                        onPressed: () {
                          Http.userLogout();
                          context.read<AppProvider>().logOut();
                        },
                        child: Text("退出"))
              ],
            ),
          );
        },
      ),
    );
  }
}
